package cn.schoolwow.util.domain.query.queryPackage;

import cn.schoolwow.quickflow.QuickFlow;
import cn.schoolwow.quickflow.QuickFlowBuilder;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.util.module.query.queryPackage.domain.QueryPackageOption;
import cn.schoolwow.util.module.query.queryPackage.flow.GetClassInstanceListFlow;
import cn.schoolwow.util.module.query.queryPackage.flow.GetClassNameListFlow;
import cn.schoolwow.util.module.query.queryPackage.service.GetClassListFlow;

import java.util.ArrayList;
import java.util.List;

public class QueryPackageResponse {
    private static QuickFlow resourceQuickFlow = QuickFlowBuilder.newInstance();

    public QueryPackageResponse(QueryPackageOption queryPackageOption) {
        resourceQuickFlow.putContextThreadLocalInstanceData(queryPackageOption);
    }

    /**
     * 获取所有类名列表
     * */
    public List<String> getClassNameList(){
        FlowContext flowContext = resourceQuickFlow.startFlow(new GetClassListFlow())
                .next(new GetClassNameListFlow())
                .execute();
        List<String> classNameList = flowContext.getData("classNameList", List.class, new ArrayList());
        return classNameList;
    }

    /**
     * 获取所有类列表
     * */
    public List<Class> getClassList(){
        FlowContext flowContext = resourceQuickFlow.startFlow(new GetClassListFlow())
                .execute();
        List<Class> classList = flowContext.getData("classList", List.class, new ArrayList());
        return classList;
    }

    /**
     * 获取所有实例列表
     * */
    public <T> List<T> getInstanceList(Class<T> clazz){
        FlowContext flowContext = resourceQuickFlow.startFlow(new GetClassListFlow())
                .next(new GetClassInstanceListFlow())
                .execute();
        List<T> instanceList = flowContext.getData("instanceList", List.class, new ArrayList());
        return instanceList;
    }
}
